package com.ym.b2b.user.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.ym.b2b.commons.dao.BaseDao;
import com.ym.b2b.user.dao.UserFavoritesDao;
import com.ym.b2b.user.sqlbean.EmSUserFavorites;
import com.zc.commons.base.Page;

@Repository
public class UserFavoritesDaoImpl<T> extends BaseDao<T> implements UserFavoritesDao {

    @Override
    public Page<EmSUserFavorites> searchPageUserProductFavorites(EmSUserFavorites emSUserFavorites,
                                                                 Page<EmSUserFavorites> page)
                                                                                             throws DataAccessException {
        page.setTotalRow(searchUserProductFavoritesNum(emSUserFavorites));
        Map<String, Object> map = new HashMap<String, Object>();

        map.put("map", emSUserFavorites);
        map.put("startrow", page.getStartRow());
        map.put("pagesize", page.getPageSize());
        map.put("pageable", page.getPageable());
        page.setRows(list("EM_S_USER_FAVORITES.searchPageEmSUserFavorites", map));
        return page;
    }

    @Override
    public Long searchUserProductFavoritesNum(EmSUserFavorites emSUserFavorites) throws DataAccessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", emSUserFavorites);
        return (Long) listNum("EM_S_USER_FAVORITES.searchPageEmSUserFavoritesNum", map);
    }

    @Override
    public int deleteUserFavorites(Long favoritesId) throws DataAccessException {
        return delete("EM_S_USER_FAVORITES.deleteEmSUserFavorites", favoritesId);
    }

    @Override
    public Object addUserFavorites(EmSUserFavorites emSUserFavorites) throws DataAccessException {

        return insert("EM_S_USER_FAVORITES.insertEmSUserFavorites", emSUserFavorites);
    }

}
